/**
 * Notes: 系统设置实体
 * Ver : CCMiniCloud Framework 2.0.15 ALL RIGHTS RESERVED BY cclinux0730 (wechat)
 * Date: 2020-11-05 19:20:00 
 */


const MultiModel = require('../../database/multi_model.js');

class SetupModel extends MultiModel {

}

/**
 * 静态方法 - 获取单条记录
 * @param {*} where 查询条件
 * @param {*} fields 字段
 * @param {*} orderBy 排序
 * @returns 单条记录
 */
SetupModel.getOne = async function(where, fields = '*', orderBy = {}) {
    try {
        const BaseModel = require('../../platform/model/base_model.js');
        const model = new BaseModel(SetupModel.CL);
        return await model.getOne(where, fields, orderBy);
    } catch (err) {
        console.error('获取设置记录失败', err);
        return null;
    }
};

/**
 * 静态方法 - 查询记录
 * @param {*} where 条件
 */
SetupModel.edit = async function(where, data) {
    try {
        const BaseModel = require('../../platform/model/base_model.js');
        const model = new BaseModel(SetupModel.CL);
        return await model.edit(where, data);
    } catch (err) {
        console.error('更新设置记录失败', err);
        return null;
    }
};

/**
 * 静态方法 - 插入记录
 * @param {*} data 数据
 */
SetupModel.insert = async function(data) {
    try {
        const BaseModel = require('../../platform/model/base_model.js');
        const model = new BaseModel(SetupModel.CL);
        return await model.insert(data);
    } catch (err) {
        console.error('插入设置记录失败', err);
        return null;
    }
};

/**
 * 静态方法 - 删除记录
 * @param {*} where 条件
 */
SetupModel.del = async function(where) {
    try {
        const BaseModel = require('../../platform/model/base_model.js');
        const model = new BaseModel(SetupModel.CL);
        return await model.del(where);
    } catch (err) {
        console.error('删除设置记录失败', err);
        return null;
    }
};

// 集合名
SetupModel.CL = MultiModel.C('setup');

SetupModel.DB_STRUCTURE = {
	_pid: 'string|true',
	SETUP_ID: 'string|true',

	SETUP_TYPE: 'string|false', //content/cache/vouch
	SETUP_KEY: 'string|true',
	SETUP_VALUE: 'object|true', // {val:}
 
	SETUP_ADD_TIME: 'int|true',
	SETUP_EDIT_TIME: 'int|true',
	SETUP_ADD_IP: 'string|false',
	SETUP_EDIT_IP: 'string|false',
};

// 字段前缀
SetupModel.FIELD_PREFIX = "SETUP_"; 


module.exports = SetupModel;

/* 
### 富文本
[{"type":"text","val":"xxx"},{"type":"img","val":"cloudId://xxxx"}]

### 导出
{"EXPORT_CLOUD_ID":"","EXPORT_EDIT_TIME":""}
*/